const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://taosha_user:apyl8XWP6LSW4JHs@101.35.6.34:27722/taosha";
const ObjectId = require('mongodb').ObjectId;

async function main() {
  const client = await MongoClient.connect(url, {useNewUrlParser: true, useUnifiedTopology: true});
  const db = client.db('taosha');


  let messages = await db.collection('messages')
    .find(

    )
    .toArray();


  for (let i = 0; i < messages.length; i++) {
    let msg = messages[i];
    let author_id = msg.author_id;

    let user = await db.collection('users').findOne({_id: ObjectId(author_id)});
    if (!user) {
      console.log(author_id, i, messages.length);
    }
  }

  client.close();

}

main();
